<template>
	<view class="jifenShare">
		<!-- #ifdef H5 -->
		<view class="block" v-show="blockShow" @click="hideBlock">
			<text class="label">点击右上角，立即分享好友</text>
			<image class="jiantou" src="../../static/images/public/11df2.png" mode=""></image>
		</view>
		<!-- #endif -->
		<view class="paySuccess">
			<image src="../../static/images/public/select.png" mode=""></image>
			<text>支付成功</text>
		</view>
		<view class="shareImg">
			<image src="https://inclusivecommunity.oss-cn-chengdu.aliyuncs.com/attach/2020-10/872ee202010161815446802.png" mode=""></image>
			<text>{{fen}}</text>
		</view>
		<view class="jifenDesc">
			<view>本次消费获得<text class="yellow">{{fen}}</text>积分</view>
			<text v-if="share_mode == 'old'">您可选收入积分到自己账户或将积分转赠好友</text>
		</view>
		<view class="btnBox" v-if="share_mode == 'old'">
			<!-- #ifndef MP-WEIXIN -->
			<view class="btn full" @tap="share(1)">转赠好友</view>
			<!-- #endif -->
			<!-- #ifdef MP-WEIXIN -->
			<button class="btn full" id="shareBtn" open-type="share" type="primary">
				转赠好友
			</button>
			<!-- #endif -->
			<view class="btn empty" @tap="share(2)">收入积分</view>
			<view class="goIndex" @tap="goIndex">去首页 >></view>
		</view>
		<view class="btnBox" v-if="share_mode == 'new'">
			<view class="btn full" @tap="goIndex">去首页</view>
		</view>
	</view>
</template>

<script>
	import {shareAction } from "@/api/pay.js"
	import wechat from '@/common/wechat.js'
	import {
		shareBaseUrl
	} from "@/api/api.js"
	export default {
		data() {
			return {
				blockShow: false,
				orderId: "",
				fen: "",
				share_mode: "",
				shareBaseUrl: ""
			};
		},
		onLoad(option) {
			//#ifdef H5
			if(uni.getSystemInfoSync().platform == 'ios') {
				if(!uni.getStorageSync("shareReload")) {
					uni.setStorageSync("shareReload",true)
					location.reload()
				} else {
					uni.removeStorageSync("shareReload")
				}
			}
			//#endif
			this.shareBaseUrl = shareBaseUrl()
			this.orderId = option.id
			this.fen = option.fen
			this.share_mode = option.share_mode
			//#ifdef H5
			let baseUrl = window.location.href.split("/pages")[0]
			wechat.share(
				"好友赠送积分啦，快来领取",
				"积分可以免费兑换商品哦，千万不要错过啦…",
				baseUrl + "/pages/public/getJifenShare?id=" + this.orderId + "&fen=" + this.fen,
				"https://inclusivecommunity.oss-cn-chengdu.aliyuncs.com/attach/2020-11/22ee3202011251339401384.png"
			)
			//#endif
		},
		onShareAppMessage: function(res) {
			if (res.from === 'button') {
				console.log(res.target)
			}
			return {
				title: "好友赠送积分啦，快来领取",
				path: '/pages/public/getJifenShare?id=' + this.orderId + '&fen=' + this.fen,
				imageUrl: "https://inclusivecommunity.oss-cn-chengdu.aliyuncs.com/attach/2020-10/872ee202010161815446802.png",
				success: function(res) {
				}
			}
		},
		methods: {
			share(type) {
				if (type == 1) {
					//#ifdef APP-PLUS
					let _this = this
					uni.share({
						provider: "weixin",
						scene: "WXSceneSession",
						type: 0,
						href: this.shareBaseUrl + 'pages/public/getJifenShare?id=' + this.orderId + '&fen=' + this.fen, 
						title: "好友赠送积分啦，快来领取",
						summary: "积分可以免费兑换商品哦，千万不要错过啦…",
						imageUrl: "https://inclusivecommunity.oss-cn-chengdu.aliyuncs.com/attach/2020-10/872ee202010161815446802.png",
						success: function(res) {
							console.log("success:" + JSON.stringify(res));
						},
						fail: function(err) {
							console.log("fail:" + JSON.stringify(err));
						}
					});
					//#endif
					//#ifdef H5
					this.blockShow = true
					//#endif
				} else {
					uni.showLoading({
						mask:true
					})
					shareAction({
						orderId: this.orderId,
						type: "no"
					}).then(res => {
						uni.hideLoading()
						uni.showToast({
							title: res.msg,
							duration: 300,
						})
						let _this = this
						setTimeout(function() {
							uni.redirectTo({
								url: "/pages/order/orderDetail?id=" + _this.orderId
							})
						},300)
					})
				}
			},
			hideBlock() {
				this.blockShow = false
			},
			goIndex() {
				uni.reLaunch({
					url:"/pages/index/index"
				})
			}
		},
		onHide() {
			this.hideBlock()
		}
	}
</script>

<style lang="scss" scoped>
	.jifenShare {
		display: flex;
		flex-direction: column;
		align-items: center;
		.block {
			position: fixed;
			left: 0;
			top: 0;
			width: 100vw;
			height: 100vh;
			background-color: rgba(0, 0, 0, .7);
			z-index: 999;
			.label{
				display: block;
				text-align: center;
				padding-top: 90rpx;
				font-size: 40rpx;
				font-family: PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
				line-height: 36rpx;
			}
			.jiantou {
				position: absolute!important;
				right: 60rpx;
				top: 10rpx;
				display: block;
				width: 65rpx;
				height: 65rpx;
			}
		}
		.paySuccess {
			padding-top: 100rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			image {
				width: 53rpx;
				height: 53rpx;
				border-radius: 50%;
				margin-right: 20rpx;
			}

			text {
				font-size: 48rpx;
				font-weight: 500;
				color: #343434;
			}
		}

		.shareImg {
			margin-top: 70rpx;
			width: 560rpx;
			height: 474rpx;
			position: relative;

			image {
				position: absolute;
				left: 0;
				top: 0;
				width: 560rpx;
				height: 474rpx;
			}

			text {
				position: absolute;
				width: 100%;
				left: 0;
				top: 300rpx;
				text-align: center;
				font-size: 48rpx;
				font-weight: 500;
				color: #fff;

				&::before {
					content: "+";
					font-size: 48rpx;
					font-weight: 500;
				}

				&::after {
					content: " 积分";
					font-size: 24rpx;
					font-weight: 500;
				}
			}
		}

		.jifenDesc {
			margin-top: 20rpx;
			display: flex;
			flex-direction: column;
			font-size: 24rpx;
			color: #343434;
			line-height: 36rpx;
			text-align: center;

			.yellow {
				color: #F9BE2E;
			}
		}

		.btnBox {
			margin-top: 100rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.btn {
				width: 600rpx;
				height: 80rpx;
				border-radius: 40rpx;
				text-align: center;
				font-weight: 500;
				line-height: 80rpx;
				font-size: 30rpx;
				box-sizing: border-box;
				margin-bottom: 40rpx;
			}

			.full {
				background: #F9BE2E;
				color: #fff;
			}

			.empty {
				border: 2rpx solid #F9BE2E;
				color: #F9BE2E;
			}
			.goIndex{
				margin-top: 70rpx;
				color: #F9BE2E;
			}
		}
	}
</style>
